<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <link media="all" rel="stylesheet" th:href="@{/lib/layui-v2.6.3/css/layui.css}">
    <link media="all" rel="stylesheet" th:href="@{/css/public.css}">

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="eidt">
    <div class="layui-form-item">
        <label class="layui-form-label required">id</label>
        <div class="layui-input-block">
            <input class="layui-input" id="userId" name="userId" readonly="readonly" type="text" value="">
            <tip>id不可修改</tip>
        </div>
    </div>
    <!--    <div class="layui-form-item">-->
    <!--        <label class="layui-form-label required">用户名</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input id="userName" type="text" name="userName" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">-->

    <!--        </div>-->
    <!--    </div>-->
    <div class="layui-form-item">
        <label class="layui-form-label required">登录账号</label>
        <div class="layui-input-block">
            <input class="layui-input" id="userAccount" name="userName" placeholder="请输入账号" readonly="readonly"
                   type="text" value="">
            <tip>账号不可修改</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">登录密码</label>
        <div class="layui-input-block">
            <input class="layui-input" id="userPassword" lay-reqtext="密码不能为空" lay-verify="required" name="password"
                   placeholder="请新输入密码" type="password" value="">
        </div>
    </div>
    <!--    <div class="layui-form-item">-->
    <!--        <label class="layui-form-label required">用户角色</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input id="userRole" type="text" name="userRole" lay-verify="required" lay-reqtext="" placeholder="角色 1为普通用户 0为管理员 2为商家" value="" class="layui-input">-->
    <!--        </div>-->
    <!--    </div>-->
    <!--    <div class="layui-form-item">-->
    <!--        <label class="layui-form-label required">用户余额</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input id="userBalance" type="text" name="userBalance" lay-verify="required" lay-reqtext="" placeholder="修改用户余额" value="" class="layui-input">-->
    <!--        </div>-->
    <!--    </div>-->
    <!--    <div class="layui-form-item">-->
    <!--        <label class="layui-form-label required">性别</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input id="userSex" readonly="readonly" type="text" name="userSex" placeholder="性别" value="" class="layui-input">-->
    <!--            <tip>性别不可修改</tip>-->
    <!--        </div>-->
    <!--    </div>-->
    <div class="layui-form-item">
        <label class="layui-form-label required">手机</label>
        <div class="layui-input-block">
            <input class="layui-input" id="userPhone" lay-reqtext="手机不能为空" lay-verify="phone" name="userPhonenumber"
                   placeholder="请输入手机" type="number" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-filter="saveBtn" lay-submit>确认保存</button>
        </div>
    </div>

</div>
</div>
<script charset="utf-8" th:src="@{/lib/layui-v2.6.3/layui.js}"></script>
<!--<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}"></script>-->
<script>
    window.onload = function (e) {
        console.log(e)
    }

    layui.use(['form'], function (obj) {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        // //给表单赋值
        // form.val("eidt", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
        //     "userName": "1756295440" // "name": "value"
        //     ,"userSex": "男"
        //     ,"userPhone": "123456789"
        //     ,"userPassword": "123456"
        //    , "userAccount":"123456"
        //     ,"userRole":1,
        //     "userBalance":100
        // });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert("点击确认修改", {
                title: '确认提交'
            }, function () {

                $.post({
                    url: "/admin/user/update",
                    data: data.field,
                    success: function (data) {
                        if (data.code == '001') {
                            //修改成功
                            layer.msg("修改成功")
                        } else {
                            //修改失败!
                            layer.msg("修改失败!")
                        }

                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        // 关闭弹出层
                        layer.close(index);
                        // 关闭后刷新父页面
                        parent.location.reload();
                        parent.layer.close(iframeIndex);
                    }
                })


            });

            return false;
        });

    });
</script>
</body>
</html>